import uploadImg from '@/libs/upload-img'
import {api} from '@/packagePages/pages/order/libs/api.js';
let _self;
export const index =  {
	props: {
		show: {type: Boolean,default: false},
		orderId: {type: Number,default: 0},
		title: {type: String,default: ""},
		reload:{type: Boolean,default: false},
		payData:{type: Object,default: {}},
		tabSubItem:{type: Number,default: 1}
	},
	data() {
		return {
			host:process.env.HOST,
			id:this.orderId,
			tabItem:this.tabSubItem,
			showBox:false,
			boxTitle:this.title,
			fileList: [],
			pReload:this.reload,
			paymentId:"",
			showPay:false,
			
			intervalId:""
		}
	},
	
	
	watch:{
		show(val){this.showBox=val;},
		
		showBox(val){
			if(val){
				this.initData();
			}else{
				this.clearTask();
			}
			this.$emit('update:show', val);
		},
		orderId(val){this.id=val;},
		title(val){this.boxTitle=val;},
		
		pReload(val){
			this.$emit('update:reload', val);
		},
		
		tabItem(val){
			this.$emit('update:tabSubItem', val);
		},

	},
	created() {
		_self = this;

	},
	
	methods: {
		async initData(){
			this.paymentId="FK"+new Date().getTime().toString()+Math.round(Math.random()*1000).toString();//付款单号
			
			if(this.intervalId) return true;
			let intervals =this.$store.state.user.intervals
			this.intervalId = setInterval(async function(){
				let pay=await api.checkPay({"id":_self.paymentId});
				if(pay&&pay=='success'){
					uni.showToast({icon:"none",title:"付款成功！"});
					clearInterval(_self.intervalId);
					_self.showPay=true;

					_self.showBox=false;
					_self.pReload=false;
					_self.pReload=true;
					
				}
			},2000);　
			
			intervals.push(this.intervalId);
			this.$store.commit("setIntervals",intervals);
		
		},
		
		clearTask(){
			this.intervalId="";
			let intervals =this.$store.state.user.intervals;
			for(let index in intervals){
				clearInterval(intervals[index]);
			}
			this.$store.commit("setIntervals",[]);
		},
		
		
		
		cancel(e){
			this.showBox=false;
		},
		confirmBox(e){
			this.showBox=false;
		},
		submitForm(){
			
		},
		
		confirmPay(){
			
		}
	

	}
}